package com.teach.controller;


import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.teach.commons.Id;
import com.teach.dto.LoginUser;
import com.teach.entity.PhotoOrder;
import com.teach.entity.PhotoOrderDetail;
import com.teach.exception.CodeException;
import com.teach.service.photo.PhotoOrderDetailService;
import com.teach.service.photo.PhotoOrderService;


@Controller
@RequestMapping("/certificate")
public class PayController {
	@Autowired
	private Id idea;
	
	@Autowired
	private PhotoOrderService service;
	
	@Autowired
	private PhotoOrderDetailService service2;

	
	
	@PostMapping("/payment.do") 
	public String doAlipy(Model model, HttpServletRequest req,LoginUser user) {
		try {
			long id=idea.nextId();
			PhotoOrder order = new PhotoOrder();
			PhotoOrderDetail orderDetail = new PhotoOrderDetail();
			orderDetail.setPhotoOrderId(id);
			orderDetail.setPhotoShopId(req.getParameter("q2"));
			order.setPhotoOrderId(id);
			order.setPhotoOrderMoney(req.getParameter("q3"));
			order.setPhotoConsigneeId(user.getUserName());
			service.insertSelective(order);
			service2.insertSelective(orderDetail);
			model.addAttribute("q", id+"");
			model.addAttribute("q2", req.getParameter("q2"));
			model.addAttribute("q3", req.getParameter("q3"));
			model.addAttribute("q4", req.getParameter("q4"));
			return "forward:certificate.alipay.trade.page.pay.html";
		} catch (Exception e) {			
			return "error-login";
			// TODO: handle exception
		}
		
		//return "forward:login.html";
		//}
	}
}
